﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Net.Mime;
using DAL;
using System.Collections.Generic;
using System.ComponentModel;
using Telerik.Web.UI;
using System.Globalization;



public partial class CSMember_UserControl_uc_LapYeuCau_Xem_LichSu : System.Web.UI.UserControl
{

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            InitData();
        }
    }

    private void InitData()
    {
        lblAlerting.Text = string.Empty;
        txtTuNgay.Text = DateTime.Now.AddDays(-15).ToString("dd/MM/yyyy");
        txtDenNgay.Text = DateTime.Now.AddDays(5).ToString("dd/MM/yyyy");
        hdfTuNgay.Value = txtTuNgay.Text.Trim();
        hdfDenNgay.Value = txtDenNgay.Text.Trim();
        hdfCSID.Value = "0";
        hdfBUOIID.Value = "0";
        GetAllCSGetListByID(-1);
    }
    private void GetAllCSGetListByID(int id)
    {
        try
        {
            AccountBO acc = new AccountBO();
            List<DAL.PRC_DTP_CS_GETLISTBYIDResult> lst = new List<DAL.PRC_DTP_CS_GETLISTBYIDResult>();
            lst = acc.CSGetListByID(id);
            if (lst != null)
            {
                ddlCS.DataSource = lst;
                ddlCS.DataTextField = "NAME";
                ddlCS.DataValueField = "CODE";
                ddlCS.DataBind();

                ListItem lstParent = new ListItem("--All--", "0");
                ddlCS.Items.Insert(0, lstParent);
                ddlCS.SelectedIndex = ddlCS.Items.IndexOf(lstParent);
            }
        }
        catch
        {
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        lblAlerting.Text = string.Empty;
        DateTime dtTuNgay = new DateTime();
        DateTime dtDenNgay = new DateTime();
        try
        {
            dtTuNgay = DateTime.ParseExact(txtTuNgay.Text.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
            dtDenNgay = DateTime.ParseExact(txtDenNgay.Text.Trim(), "dd/MM/yyyy", CultureInfo.InvariantCulture);
            hdfTuNgay.Value = txtTuNgay.Text.Trim();
            hdfDenNgay.Value = txtDenNgay.Text.Trim();
        }
        catch
        {
            lblAlerting.Text = "Bạn chưa nhập ngày hoặc ngày không đúng!";
            return;
        }
        hdfCSID.Value = ddlCS.SelectedValue;
        DeliveryBO del = new DeliveryBO();
        List<ZD_PRC_ZD_DELIVERY_SO_TEMP_CS_SEARCHResult> result = new List<ZD_PRC_ZD_DELIVERY_SO_TEMP_CS_SEARCHResult>();
        result = del.Delivery_SO_Temp_CS_Search(dtTuNgay, dtDenNgay, int.Parse(hdfCSID.Value));
        grdList.DataSource = result;
        grdList.DataBind();
    }

    protected void grdList_RowEditing(object sender, GridViewEditEventArgs e)
    {
        lblAlerting.Text = string.Empty;
        grdList.EditIndex = e.NewEditIndex;
        string id = grdList.DataKeys[e.NewEditIndex].Value.ToString();
        string strNgayLamPhieu = ((HiddenField)grdList.Rows[e.NewEditIndex].Cells[1].FindControl("hdflISTINGNGAYLAMPHIEU")).Value;
        string strBUOIID = ((HiddenField)grdList.Rows[e.NewEditIndex].Cells[2].FindControl("hdflISTINGBUOIID")).Value;

        string Link = "../csmem/hisdetail_" + strNgayLamPhieu.Replace("/", "") + "_" + strBUOIID + "_" + id;
        Response.Redirect(Link);

    }

    protected void grdList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdList.PageIndex = e.NewPageIndex;
        DateTime dtTuNgay = DateTime.ParseExact(hdfTuNgay.Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);
        DateTime dtDenNgay = DateTime.ParseExact(hdfDenNgay.Value, "dd/MM/yyyy", CultureInfo.InvariantCulture);

        DeliveryBO del = new DeliveryBO();
        List<ZD_PRC_ZD_DELIVERY_SO_TEMP_CS_SEARCHResult> result = new List<ZD_PRC_ZD_DELIVERY_SO_TEMP_CS_SEARCHResult>();
        result = del.Delivery_SO_Temp_CS_Search(dtTuNgay, dtDenNgay, int.Parse(hdfCSID.Value));
        grdList.DataSource = result;
        grdList.DataBind();
    }
}
